<template>
    <view class="create-post">
        <han-status-bar />
        <post-header />

        <!-- 媒体上传 -->
        <media-upload />
        <!-- 帖子表单 -->
        <post-from ref="postFormRef" />
        <!-- 高级设置 -->
        <post-setting />

        <!-- 发布按钮 -->
        <view class="post-button" @click="handleSubmit">
            <han-icon name="post" size="38" />
            <text class="button-title">点击发布</text>
        </view>
    </view>
</template>

<script setup>
import { usePostStore } from '@/stores/postStores';

import postHeader from './components/postHeader.vue';
import postFrom from './components/postFrom.vue';
import mediaUpload from './components/mediaUpload.vue';
import postSetting from './components/postSetting.vue';

const postStore = usePostStore();

// 处理提交帖子
const handleSubmit = async () => {
    if (!postStore.formData.title || !postStore.formData.content) {
        uni.showToast({
            title: '标题和内容不能为空',
            icon: 'none'
        });

        return;
    }

    if (!postStore.selectedCategoryId) {
        uni.showToast({
            title: '请选择话题分类',
            icon: 'none'
        });
        return;
    }

    await postStore.submitPost();
};
</script>

<style lang="scss">
.create-post {
    width: 100%;
    height: 100%;

    .post-button {
        display: flex;
        align-items: center;
        justify-content: center;
        height: 80rpx;
        width: 50%;
        border-radius: 10rpx;
        margin: 30rpx auto;
        border: 1rpx solid $han-global-border-color;

        .button-title {
            margin: 0 10rpx;
        }
    }
}
</style>
